package com.wl.lib.http

import android.content.Context
import android.net.ConnectivityManager
import com.wl.lib.base.R
import com.wl.lib.utils.ApplicationHelper
import com.wl.lib.utils.ResUtils


// Created by wangliang on 2024/4/28.
object NetworkHelper {

    fun isNetworkAvailable(context: Context): Boolean {
        val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
            ?: return false
        return cm.activeNetworkInfo?.isConnected == true
    }

    fun getDefaultRequestErrorMsg() = if (isNetworkAvailable(ApplicationHelper.getInstance())) {
        ResUtils.getString(R.string.no_network)
    } else {
        ResUtils.getString(R.string.default_request_error)
    }

}